package ${package.Controller};

    import com.daqian.chance.core.rest.RestResult;
    import ${cfg.packageParent}.po.req.${entity}Req;
    import ${cfg.packageParent}.service.I${entity}Service;
import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
public class ${table.controllerName} {
    </#if>

    @Autowired
    private I${entity}Service i${entity}Service;


    /**
     * 分页查询 ${table.comment!}
     *
     * @author ${author}
     */
    @GetMapping("page")
    public RestResult page(${entity}Req ${table.entityPath}Req) {
        return RestResult.ok(i${entity}Service.page(${table.entityPath}Req));
    }

    /**
     * 根据id查询 ${table.comment!}
     *
     * @author ${author}
     */
    @GetMapping("info/{${table.entityPath}Id}")
    public RestResult info(@PathVariable("${table.entityPath}Id") Long ${table.entityPath}Id) {
        return RestResult.ok(i${entity}Service.getById(${table.entityPath}Id));
    }

    /**
     * 保存 ${table.comment!}
     *
     * @author ${author}
     */
    @PostMapping("save")
    public RestResult save(@RequestBody ${entity}Req ${table.entityPath}Req) {
    i${entity}Service.save(${table.entityPath}Req.convertToEntity());
        return RestResult.ok();
    }

    /**
     * 更新 ${table.comment!}
     *
     * @author ${author}
     */
    @PostMapping("update/{${table.entityPath}Id}")
    public RestResult remove(@PathVariable("${table.entityPath}Id") Long ${table.entityPath}Id, @RequestBody ${entity}Req ${table.entityPath}Req) {
    i${entity}Service.updateById(${table.entityPath}Req.convertToEntity().setId(${table.entityPath}Id));
        return RestResult.ok();
    }

    /**
     * 根据id删除 ${table.comment!}
     *
     * @author ${author}
     */
    @DeleteMapping("{${table.entityPath}Id}")
    public RestResult delete(@PathVariable("${table.entityPath}Id") Long ${table.entityPath}Id) {
    i${entity}Service.removeById(${table.entityPath}Id);
    return RestResult.ok();
    }

}
</#if>
